package com.nhutcm.sms.Utils;

import java.util.ArrayList;
import java.util.List;

import android.util.Base64;

import com.nhutcm.sms.Utils.LogUtils.Level;

public class StringUtils {
	public static final String TAG = "StringUtils";

	public static String EncodeBase64(String text) {
		String value = null;
		try {
			byte[] data = text.getBytes("UTF-8");
			value = Base64.encodeToString(data, Base64.DEFAULT);
		} catch (Exception ex) {
			LogUtils.write(Level.ERROR, ex.getMessage());
		}
		return value;
	}

	public static String DecodeBase64(String text) {
		String value = null;
		try {
			byte[] data = Base64.decode(text, Base64.DEFAULT);
			value = new String(data, "UTF-8");
		} catch (Exception ex) {
			LogUtils.write(Level.ERROR, ex.getMessage());
		}
		return value;
	}

	public static List<String> splitByLength(String text, int len) {
		List<String> strings = new ArrayList<String>();
		int index = 0;
		while (index < text.length()) {
			strings.add(text.substring(index,
					Math.min(index + len, text.length())));
			index += len;
		}
		return strings;
	}

}
